package com.sunny.core.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CommonDateUtils {
	
	/**
	 * 由生日获得年龄
	 * 
	 * @param oBirthDay
	 *            生日
	 * @return 年龄
	 */
	public static int calcAge(Date oBirthDay) {
		int iAge;
		Calendar oCalendarToday = Calendar.getInstance();
		oCalendarToday.setTime(new java.util.Date());

		Calendar oCalendarBirthday = Calendar.getInstance();
		oCalendarBirthday.setTime(oBirthDay);

		Calendar oCalendarTemp = Calendar.getInstance();
		oCalendarTemp.set(oCalendarToday.get(Calendar.YEAR), oCalendarBirthday.get(Calendar.MONTH), oCalendarBirthday.get(Calendar.DATE));

		iAge = oCalendarToday.get(Calendar.YEAR)- oCalendarBirthday.get(Calendar.YEAR);
		if (!oCalendarToday.after(oCalendarTemp)) {
			iAge--;
		}
		return iAge;
	}
	
	/**
	 * 
	 *  格式化输出当前时间
	 * 
	 */
	public static String getCurrentDate(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(new Date());
	}	
	
}
